home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_qt3.idb / usr / freeware / Qt / examples / biff / biff.cpp.z / biff.cpp
Encoding:
C/C++ Source or Header  |  2002-04-08  |  1.7 KB  |  77 lines

  1. /****************************************************************************
  2. ** $Id:  qt/biff.cpp   3.0.3   edited Oct 12 12:18 $
  3. **
  4. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  5. **
  6. ** This file is part of an example program for Qt.  This example
  7. ** program may be used, distributed and modified without limitation.
  8. **
  9. *****************************************************************************/
  10.  
  11. #include "biff.h"
  12. #include <qstring.h>
  13. #include <qfileinfo.h>
  14. #include <qpainter.h>
  15.  
  16. #include <unistd.h>
  17. #include <stdlib.h>
  18.  
  19. #include "bmp.cpp"
  20.  
  21.  
  22. Biff::Biff( QWidget *parent, const char *name )
  23.     : QWidget( parent, name, WType_Modal )
  24. {
  25.     QFileInfo fi = QString(getenv( "MAIL" ));
  26.     if ( !fi.exists() ) {
  27.     QString s( "/var/spool/mail/" );
  28.     s += getlogin();
  29.     fi.setFile( s );
  30.     }
  31.  
  32.     if ( fi.exists() ) {
  33.     mailbox = fi.absFilePath();
  34.     startTimer( 1000 );
  35.     }
  36.  
  37.     setMinimumSize( 48, 48 );
  38.     setMaximumSize( 48, 48 );
  39.     resize( 48, 48 );
  40.  
  41.     hasNewMail.loadFromData( hasmail_bmp_data, hasmail_bmp_len );
  42.     noNewMail.loadFromData( nomail_bmp_data, nomail_bmp_len );
  43.  
  44.     gotMail = FALSE;
  45.     lastModified = fi.lastModified();
  46. }
  47.  
  48.  
  49. void Biff::timerEvent( QTimerEvent * )
  50. {
  51.     QFileInfo fi( mailbox );
  52.     bool newState = ( fi.lastModified() != lastModified &&
  53.               fi.lastModified() > fi.lastRead() );
  54.     if ( newState != gotMail ) {
  55.     if ( gotMail )
  56.         lastModified = fi.lastModified();
  57.     gotMail = newState;
  58.     repaint( FALSE );
  59.     }
  60. }
  61.     
  62.  
  63. void Biff::paintEvent( QPaintEvent * )
  64. {
  65.     if ( gotMail )
  66.     bitBlt( this, 0, 0, &hasNewMail );
  67.     else
  68.     bitBlt( this, 0, 0, &noNewMail );
  69. }
  70.  
  71.  
  72. void Biff::mousePressEvent( QMouseEvent * )
  73. {
  74.     QFileInfo fi( mailbox );
  75.     lastModified = fi.lastModified();
  76. }
  77.